package com.pearadmin.pro.modules.school.service.impl;

import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.common.web.base.page.PageResponse;
import com.pearadmin.pro.common.web.base.page.Pageable;

import com.pearadmin.pro.modules.school.domain.CourseBasicInformation;
import com.pearadmin.pro.modules.school.domain.TeachingMaterial;
import com.pearadmin.pro.modules.school.param.TeachingMaterialRequest;
import com.pearadmin.pro.modules.school.repository.TeachingMaterialRepository;
import com.pearadmin.pro.modules.school.service.TeachingMaterialService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 教材Service业务层处理
 *
 * @author ChenJian
 * @date 2021-08-29
 */
@Service
public class TeachingMaterialServiceImpl extends ServiceImpl<TeachingMaterialRepository, TeachingMaterial> implements TeachingMaterialService
{
    @Resource
    private TeachingMaterialRepository teachingMaterialRepository;

    /**
     * 查询教材
     * @param request
     * @return 教材 分页集合
     * */
    @Override
    public PageResponse<TeachingMaterial> page(TeachingMaterialRequest request)
    {
        LambdaQueryWrapper<TeachingMaterial> query = new LambdaQueryWrapper<TeachingMaterial>();
        query.eq(ObjectUtil.isNotEmpty(request.getTmName()),TeachingMaterial::getTmName,request.getTmName());
        query.eq(ObjectUtil.isNotEmpty(request.getAuthorName()),TeachingMaterial::getAuthorName,request.getAuthorName());
        query.eq(ObjectUtil.isNotEmpty(request.getPress()),TeachingMaterial::getTmName,request.getPress());
        query.eq(ObjectUtil.isNotEmpty(request.getCreateBy()),TeachingMaterial::getTmName,request.getCreateBy());
        query.ge(ObjectUtil.isNotEmpty(request.getStatCreateTime()),TeachingMaterial::getTmName,request.getStatCreateTime());
        query.le(ObjectUtil.isNotEmpty(request.getEndCreateTime()),TeachingMaterial::getTmName,request.getEndCreateTime());
        return Pageable.of(request,(()->  teachingMaterialRepository.selectList(query)));
    }

    /**
     * 查询教材
     *
     * @param id 教材ID
     * @return 教材
     */
    @Override
    public TeachingMaterial selectTeachingMaterialById(Long id)
    {
        return teachingMaterialRepository.selectById(id);
    }

}
